/*
 * This file is part of Super Luigi Bros.
 * Super Luigi Bros is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Super Luigi Bros is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Super Luigi Bros.  If not, see <http://www.gnu.org/licenses/>.
 */

package luigibros.displayComponents;

import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;

import java.awt.Rectangle;
/** This class detects whether or not a collision 
 *  has occurred and then processes them and returns
 *  a Map containing a key using Character and holds
 *  values stored in a List<Character>.
 *  @author zking918@gmail.com
 */
public class CollisionDetector
{
	/** Receives a Map holding Rectangle as key Character as value
	 *  then returns a Map with Character as key and List<Character> as
	 *  value
	 *  @param - Map<Rectangle, Character>
	 *  @return - A map containing Character as key and List<Character> as value
	 *  @author - zking918@gmail.com
	 */
	public Map<Character, List<Character>> processCollision(Map<Rectangle, Character> information)
	{
		
		//variables
		List<Rectangle> rectangles = new ArrayList<Rectangle>(information.keySet());
		Map<Character, List<Character>> collisions = new HashMap<Character, List<Character>>();
		Rectangle rectangleX = new Rectangle();
		Rectangle rectangleY = new Rectangle();
		
		information.get(information);
		
		for(int x = 0; x < rectangles.size(); x++)
		{
			List<Character> characters = new ArrayList<Character>();
			for(int y = 0; y < rectangles.size(); y++)
			{
				if(x != y)
				{
					rectangleX = rectangles.get(x);
					rectangleY = rectangles.get(y);
					if(rectangleX.intersects(rectangleY))
					{
						characters.add(information.get(rectangles.get(y)));
					}
				}
			}
			if(characters.size() == 0)
				collisions.put(information.get(rectangleX), characters);
		}
		
		return collisions;
	}
}
